layui.use(['layer', 'element', 'laytpl', 'jquery'], function() {
	//引入模块
	var layer = layui.layer,
		element = layui.element,
		laytpl = layui.laytpl,
		$ = layui.jquery;

	if (localStorage.set != null) {
		//加载页面发生请求拿到数据
		$.ajax({
			url: "http://localhost:8080/sc/admin?type=home",
			async: true, //异步
			type: "POST",
			headers: {
				"token": localStorage.token
			},
			success: function(data) {
				//这里找id必须用js
				if (data.code == 'TokenFailed') {
					//删除token set
					delete localStorage.token;
					delete localStorage.set;
					layer.msg('登录失效，请重新登录！')
					setTimeout(function() {
						//调用父页面方法
						parent.tz();
					}, 1000);
				} else {
					var getTpl = document.getElementById('homemb').innerHTML,
						view = document.getElementById('homemoban');
					laytpl(getTpl).render(data, function(html) {
						view.innerHTML = html;
					});
				}
			}
		});

	} else {
		layer.msg('您还没有登录！')
		setTimeout(function() {
			parent.tz();
			//window.location.replace('admin_login.html');
		}, 1000);
	}

	//拿到系统时间
	function currentTime() {
		var d = new Date(),
			str = '';
		str += d.getFullYear() + '年';
		str += d.getMonth() + 1 + '月';
		str += d.getDate() + '日';
		str += d.getHours() + '时';
		str += d.getMinutes() + '分';
		str += d.getSeconds() + '秒';
		return str;
	}

	//动态设置时间显示文本
	setInterval(function() {
		$('#time').html(currentTime)
	}, 1000);
});
